class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int, int> hash;
        vector<int> ans(2);
        int n = nums.size();
        for (int i = 0; i < n; ++i)
        {
            if (hash.find(target - nums[i]) != hash.end())
            {
                ans[0] = hash[target - nums[i]];
                ans[1] = i;
            }
            else
                hash[nums[i]] = i;
        }
        return ans;
    }
};